/*
 * Copyright (c) 2020-2022. the original authors and DEPSEA.ORG
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
package org.depsea.log.notification.link;

import lombok.extern.slf4j.Slf4j;
import org.depsea.log.notification.Message;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * 链路追踪
 *
 * @author Wang Chengwei
 * @since 1.0.0 [2022/12/3 16:31]
 */
@Slf4j
public class TrackingLink implements Link {

    private final String baseUrl;

    public TrackingLink(String baseUrl) {
        this.baseUrl = baseUrl;
    }


    @Override
    public String getLinkName() {
        return "查看链路追踪日志";
    }

    @Override
    public String getLinkUrl(Message message) {
        try {
            String encodeUrl = URLEncoder.encode(this.baseUrl, "UTF-8");
            return "dingtalk://dingtalkclient/page/link?url=" + encodeUrl + "&pc_slide=false";
        } catch (UnsupportedEncodingException e) {
            log.error(e.getMessage(), e);
            return this.baseUrl;
        }
    }

}
